let obj = {
    name: "奉先",
    age: 35,
};

/**
 * Proxy构造函数两个参数
 *   代理对象（target）
 *   handler对象
 */
let proxy = new Proxy(obj, {

    /**
     * 用于拦截某个属性的读取操作
     * @param {*} target 目标对象
     * @param {*} property 属性名
     * @param {*} receiver proxy实例本身，可选参数
     * @returns 
     */
    get(target, property, receiver) {
        console.log("target = ", target);
        console.log("property = ", property);
        console.log("receiver = ", receiver);
        // return target[property];
        return Reflect.get(target, property,receiver);
    },

    /**
     * 方法用来拦截某个属性的赋值操作
     * @param {*} target 目标对象
     * @param {*} property 属性名
     * @param {*} value 属性值
     * @param {*} receiver Proxy实例本身，可选参数
     */
    set(target, property, value, receiver) {
        console.log("要设置对象属性？我拦截到了~");
        console.log("要修改成" + value + "?");
        console.log("我就不给你改，我改成666");
        target[property] = 666;
        // Reflect.set(target, key, value, receiver)
    },

})

console.log("proxy.name = ",proxy.name);
proxy.age = 20;
console.log("obj.age = ",obj.age);
